You are here: TI-Nspire™ Technology Program Editor eGuide > TI-Nspire™ Technology Program Editor Guide > Getting Started with the Program Editor > Getting Values into a Program

Getting Values into a Program

You can choose from several methods to supply the values that a function or program uses in calculations.

Embedding the Values Within the Program or Function

This method is useful primarily for values that must be the same each time the program or function is used.

1. Define the program.

Define calculatearea()=

Prgm

w:=3

h:=23.64

area:=w*h

Disp area

EndPrgm

2. Run the program.

calculatearea()

 

70.92

Letting the User Assign the Values to Variables

A program or function can refer to variables created beforehand. This method requires users to remember the variable names and to assign values to them before using the object.

1. Define the program.

Define calculatearea()=

Prgm

area:=w*h

Disp area

EndPrgm

2. Supply the variables, and then run the program.

w:=3 : h:=23.64

calculatearea()

 

 

70.92

Letting the User Supply the Values as Arguments

This method lets users pass one or more values as arguments within the expression that calls the program or function.

The following program, volcyl, calculates the volume of a cylinder. It requires the user to supply two values: height and radius of the cylinder.

1. Define the volcyl program.

Define volcyl(height,radius) =

Prgm

Disp "Volume =", approx(p ¦ radius2 ¦ height)

EndPrgm

2. Run the program to display the volume of a cylinder with a height of 34 mm and a radius of 5 mm.

volcyl(34,5)               Volume = 534.071

Note: You do not have to use the parameter names when you run the volcyl program, but you must supply two arguments (as values, variables, or expressions). The first must represent the height, and the second must represent the radius.

Requesting the Values from the User (Programs Only)

You can use the Request and RequestStr commands in a program to make the program pause and display a dialog box prompting the user for information. This method does not require users to remember variable names or the order in which they are needed.

You cannot use the Request or RequestStr command in a function.

1. Define the program.

Define calculatearea()=

Prgm

  Request "Width: ",w

  Request "Height: ",h

area:=w*h

EndPrgm

2. Run the program and respond to the requests.

calculatearea() : area 

Width: 3          (3 entered as a response)

Height: 23.64  (23.64 entered as a response)

 

 

 

 

70.92

Use RequestStr instead of Request when you want the program to interpret the user’s response as a character string rather than a math expression. This avoids requiring the user to enclose the response in quotation marks (““).